// ContactInfo.cs
//
//  Copyright (C) 2008 Jacek Trubłajewicz
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//

using System;
using Mono.Unix;
using HAKGERSoft;

namespace wxGadu
{
	public class ContactInfo : IComparable<ContactInfo>
	{
		/// <summary>
		/// Unified Identification Number of user in GG network
		/// </summary>
		private int uin;
		/// <summary>
		/// Name that will be visible in application
		/// </summary>
		private string name;
		/// <summary>
		/// User status from DotGadu.GaduPacketConstans.GG_STATUS_*
		/// </summary>
		private int status;
		/// <summary>
		/// User status description message
		/// </summary>
		private string description;
		private string firstname;
		private string lastname;
		private string location;
		private string phone;
		/// <summary>
		/// Position (id) on the Contacts ListCtrl
		/// </summary>
		private int position;
		/// <summary>
		/// <c>wx.Bitmap</c> which keeps contact avatar (photo)
		/// </summary>
		private wx.Bitmap photo;
		private wx.Bitmap photoSmall;
			
		/// <summary>
		/// Ctor
		/// </summary>
		public ContactInfo()
		{
			this.status = StatusConstans.offline;
			this.position = -1;
			this.description = String.Empty;
			this.phone = string.Empty;
			this.photo = null;
			this.photoSmall = null;
			this.location = string.Empty;
		}

		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="uin">
		/// A <see cref="System.Int32"/>
		/// contacts uin
		/// </param>
		/// <param name="name">
		/// A <see cref="System.String"/>
		/// contacts name
		/// </param>
		public ContactInfo(int uin, string name) : this()
		{
			if (uin == 0 || name == null)
				throw new ArgumentNullException();
			if (uin <= 0 || name == string.Empty)
				throw new ArgumentOutOfRangeException();
			this.uin = uin;
			this.name = name;
		}

		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="uin">
		/// A <see cref="System.Int32"/>
		/// contacts uin
		/// </param>
		/// <param name="name">
		/// A <see cref="System.String"/>
		/// contacts name
		/// </param>
		/// <param name="firstname">
		/// A <see cref="System.String"/>
		/// contacts firstname
		/// </param>
		/// <param name="lastname">
		/// A <see cref="System.String"/>
		/// contacts lastname
		/// </param>
		/// <param name="location">
		/// A <see cref="System.String"/>
		/// contacts location
		/// </param>
		/// <param name="photo">
		/// A <see cref="wx.Bitmap"/>
		/// contacts avatar
		/// </param>
		/// <param name="photoSmall">
		/// A <see cref="wx.Bitmap"/>
		/// contacts avatar in small size for 
		/// <c>MainFrame.BottomWindow.InfoPanel</c>
		/// </param>
		/// <param name="phone">
		/// A <see cref="System.String"/>
		/// contacts phone number
		/// </param>
		public ContactInfo(int uin, string name, string firstname, string lastname, string location,
		                   wx.Bitmap photo, wx.Bitmap photoSmall, string phone) : this(uin, name)
		{
			if (firstname == null)
				throw new ArgumentNullException();
			this.firstname = firstname;
			if (lastname == null)
				throw new ArgumentNullException();
			this.lastname = lastname;
			if (location == null)
				throw new ArgumentNullException();
			this.location = location;
			if (photo == null)
				throw new ArgumentNullException();
			this.photo = photo;
			this.photoSmall = photoSmall;
			if (phone == null)
				throw new ArgumentNullException();
			this.phone = phone;
		}

		//// <value>
		/// Contacts UIN
		/// </value>
		public int Uin
		{
			get { return uin;	}

			set { //TODO: check uin
					uin = value;	}
		}

		//// <value>
		/// Contacts name
		/// </value>
		public string Name
		{
			get { return name; }

			set { name = value; }
		}

		//// <value>
		/// Contacts firstname
		/// </value>
		public string Firstname
		{
			get { return firstname; }

			set { firstname = value; }
		}

		//// <value>
		/// Contacts lastname
		/// </value>
		public string Lastname
		{
			get { return lastname; }

			set { lastname = value; }
		}

		//// <value>
		/// Contacts location
		/// </value>
		public string Location
		{
			get { return location; }

			set { location = value; }
		}

		//// <value>
		/// Position of contact on 
		/// <c>Gadu.Users</c> list
		/// </value>
		public int Position
		{
			get { return position; }

			set { position = value; }
		}

		//// <value>
		/// Contacts avatar
		/// </value>
		public wx.Bitmap Photo
		{
			get { return photo; }

			set { photo = value; }
		}
		
		//// <value>
		/// Contacts avatar in small size
		/// </value>
		public wx.Bitmap PhotoSmall
		{
			get { return photoSmall; }

			set { photoSmall = value; }
		}

		//// <value>
		/// Contacts phone number
		/// </value>
		public string Phone
		{
			get { return phone; }

			set { phone = value; }
		}

		//// <value>
		/// Contacts status
		/// </value>
		public int Status
		{
			get { return status; }

			set
			{
				if (value == StatusConstans.online ||
				    value == StatusConstans.onlineDescr ||
				    value == StatusConstans.away ||
				    value == StatusConstans.awayDescr ||
				    value == StatusConstans.invisible ||
				    value == StatusConstans.invisibleDescr ||
				    value == StatusConstans.offline ||
				    value == StatusConstans.offlineDescr ||
				    value == StatusConstans.blocked 
				   )
				{
					status = value;
				}
				else
				{
					throw new ArgumentOutOfRangeException(Catalog.GetString("Status value must be one of StatusConstans.*"));
				}
			}
		}

		//// <value>
		/// Contact description
		/// </value>
		public string Description
		{
			get { return description; }

			set { description = value; }
		}

		/// <summary>
		/// Compare
		/// </summary>
		/// <param name="other">
		/// A <see cref="ContactInfo"/>
		/// </param>
		/// <returns>
		/// A <see cref="System.Int32"/>
		/// </returns>
		public int CompareTo(ContactInfo other)
		{
			return name.CompareTo(other.name);
		}
	}
}
